#include <stdio.h>
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

int main()
{
    //stdout -> 1
    printf("hello printf 1\n");
    fprintf(stdout, "hello fprintf 1\n");
    errno = 3;
    //stderr -> 2
    perror("hello perror 2");//stderr


    const char *s1 = "hello world 1\n";
    write(1, s1, strlen(s1));

    const char *s2 = "hello world 2\n";
    write(2, s2, strlen(s2));

    //cout -> 1
    std::cout << "hello cout 1" << std::endl;

    //cerr -> 2
    std::cerr << "hello cerr 2" << std::endl;

    
    
 //   close(1);
 //   int fd = open("log.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
 //   if(fd < 0)
 //   {
 //       perror("open");
 //       return 0;
 //   }

 //   printf("hello world:%d\n", fd);//stdout -> 1 数据会暂存在stdout的缓冲区中
 //   fflush(stdout);
 //   
 //   //const char *msg = "hello world\n";
 //   //write(fd, msg, strlen(msg));

 //   close(fd);//fd -> 1, 数据在缓冲区中，但是对应的fd先关了，数据便无法刷新了

 //   return 0;
}
